package br.com.sol.controle;

import java.io.IOException;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;

public class ThreadServidor extends Thread {
	private BluetoothServerSocket serverSocket;
	private BluetoothSocket clientSocket;
	private BluetoothAdapter adaptador;
	
	public void run() {
		try {
			serverSocket = adaptador.listenUsingRfcommWithServiceRecord(Bluetooth.SERVICO, Bluetooth.MEU_UUID);
			clientSocket = serverSocket.accept();
			TrataSocket.tratar(clientSocket, Bluetooth.threadComunicacao);
			
		} catch (IOException e) {
			//telaHandler.obtainMessage(MSG_DESCONECTOU, e.getMessage()+"[1]").sendToTarget();
			e.printStackTrace();
		}
	}
	
	public void iniciar(){
		start();
	}
	
	public void parar(){
		try {
			serverSocket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
